<?php

namespace App\Http\Controllers;

use App\Exports\Weather\WeatherExport;
use App\Http\Resources\BaseResource;
use App\Repositories\Contracts\WeatherInterface;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use MakeRep\Controllers\BaseController;

class WeatherController extends BaseController
{
    private $cityInterface = null;
    public function __construct(WeatherInterface $interface)
    {
        parent::__construct($interface);
    }

    /**
     * 天气下载
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
     */
    public function download(Request $request){
        ini_set('memory_limit', '1024M');
        return Excel::download(new WeatherExport(),'天气'.date('YmdHis').'.xlsx');
    }

    /**
     * 天气列表
     * @param Request $request
     * @return BaseResource
     */
    public function ajaxLists(Request $request)
    {
        //城市天气
        $departCityWeather = $this->interface->cityWeather($request->depart_code);
        $arrivedCityWeather = $this->interface->cityWeather($request->arrived_code);

        return new BaseResource(['depart_city_weather'=>$departCityWeather,'arrived_city_weather'=>$arrivedCityWeather]);
    }
}